package com.zb.sannuo.thereport.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zb.sannuo.common.domain.search.JCFrequency;
import com.zb.sannuo.common.domain.vo.ReportVo;
import com.zb.sannuo.common.result.Result;
import com.zb.sannuo.common.result.ResultCode;
import com.zb.sannuo.thereport.service.ConsumerDateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/consumer")
@Api(tags = "报表管理模块",description = "对消费者数据进行CRUD操作")
@CrossOrigin
public class ConsumerDataController {

    @Resource
    private ConsumerDateService consumerDateServiceImpl;

    @ApiOperation(value = "查询检测频次排行",notes = "查询检测频次排行",httpMethod = "GET")
    @RequestMapping(value = "findFr",method = RequestMethod.GET)
    public Result findfrequency(Integer page,Integer limit,String searchParams) throws Exception{

        ObjectMapper mapper = new ObjectMapper();
        ReportVo reportVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            reportVo = mapper.readValue(searchParams, ReportVo.class);
        }

        Page frequencyPage = consumerDateServiceImpl.FrequencyPage(page, limit, reportVo);
        return Result.ok(ResultCode.SUCCESS,frequencyPage.getTotal(),frequencyPage.getRecords());
    }

    @ApiOperation(value = "查询月度数据检测量排名",notes = "查询月度数据检测量排名",httpMethod = "GET")
    @RequestMapping(value = "findJcl",method = RequestMethod.GET)
    public Result findJcl(Integer page,Integer limit,String searchParams) throws Exception{

        ObjectMapper mapper = new ObjectMapper();
        ReportVo reportVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            reportVo = mapper.readValue(searchParams, ReportVo.class);
        }

        Page jclPage = consumerDateServiceImpl.JclPage(page, limit, reportVo);
        return Result.ok(ResultCode.SUCCESS,jclPage.getTotal(),jclPage.getRecords());
    }

    @ApiOperation(value = "查询月度数据异常率排名",notes = "查询月度数据异常率排名",httpMethod = "GET")
    @RequestMapping(value = "findYcl",method = RequestMethod.GET)
    public Result findYcl(Integer page,Integer limit,String searchParams) throws Exception{

        ObjectMapper mapper = new ObjectMapper();
        ReportVo reportVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            reportVo = mapper.readValue(searchParams, ReportVo.class);
        }

        Page yclPage = consumerDateServiceImpl.YclPage(page, limit, reportVo);
        return Result.ok(ResultCode.SUCCESS,yclPage.getTotal(),yclPage.getRecords());
    }

    @ApiOperation(value = "查询检测指标异常数据",notes = "查询检测指标异常数据",httpMethod = "GET")
    @RequestMapping(value = "findData",method = RequestMethod.GET)
    public Result findData(Integer page,Integer limit,String searchParams) throws Exception{

        ObjectMapper mapper = new ObjectMapper();
        ReportVo reportVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            reportVo = mapper.readValue(searchParams, ReportVo.class);
        }
        Page data = consumerDateServiceImpl.findData(page, limit, reportVo);
        return Result.ok(ResultCode.SUCCESS,data.getTotal(),data.getRecords());
    }

    @ApiOperation(value = "查询检测指标异常率人群分布",notes = "查询检测指标异常率人群分布",httpMethod = "GET")
    @RequestMapping(value = "findCrowd",method = RequestMethod.GET)
    public Result findCrowd(Integer page,Integer limit,String searchParams) throws Exception{

        ObjectMapper mapper = new ObjectMapper();
        ReportVo reportVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            reportVo = mapper.readValue(searchParams, ReportVo.class);
        }
        Page crowd = consumerDateServiceImpl.findCrowd(page, limit, reportVo);
        return Result.ok(ResultCode.SUCCESS,crowd.getTotal(),crowd.getRecords());
    }

}
